package emf2gwtbridge.generators;

import emf2gwtbridge.*;
import org.eclipse.emf.codegen.ecore.genmodel.*;

public class Service
{
  protected static String nl;
  public static synchronized Service create(String lineSeparator)
  {
    nl = lineSeparator;
    Service result = new Service();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package ";
  protected final String TEXT_2 = ";";
  protected final String TEXT_3 = NL + NL + "public class ";
  protected final String TEXT_4 = " extends ";
  protected final String TEXT_5 = "<";
  protected final String TEXT_6 = ", Long> {" + NL + "" + NL + "public ";
  protected final String TEXT_7 = " create(Class<? extends ";
  protected final String TEXT_8 = "> clazz) {";
  protected final String TEXT_9 = NL + "\treturn null;";
  protected final String TEXT_10 = NL + "\treturn new ";
  protected final String TEXT_11 = "();";
  protected final String TEXT_12 = NL + "}" + NL + "" + NL + "public Long getId(";
  protected final String TEXT_13 = " domainObject) {" + NL + "\treturn domainObject.getId();" + NL + "}" + NL + "" + NL + "public ";
  protected final String TEXT_14 = " find(Class<? extends ";
  protected final String TEXT_15 = "> clazz, Long id) {" + NL + "\treturn (";
  protected final String TEXT_16 = ") ";
  protected final String TEXT_17 = ".getFromBuffer(clazz, id);" + NL + "}" + NL + "" + NL + "public Object getVersion(";
  protected final String TEXT_18 = " domainObject) {" + NL + "\treturn domainObject.getVersion();" + NL + "}" + NL + "" + NL + "public Class<";
  protected final String TEXT_19 = "> getDomainType() {" + NL + "\treturn ";
  protected final String TEXT_20 = ".class;" + NL + "}" + NL + "" + NL + "public Class<Long> getIdType() {" + NL + "\treturn Long.class;" + NL + "}" + NL + "" + NL + "}";
  protected final String TEXT_21 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    GenClass genClass = (GenClass)argument; GenPackage genPackage = genClass.getGenPackage(); GenModel genModel = genPackage.getGenModel();
    stringBuffer.append(TEXT_1);
    stringBuffer.append(GeneratorUtils.getServicePackage(genPackage));
    stringBuffer.append(TEXT_2);
    genModel.markImportLocation(stringBuffer, genPackage);
    stringBuffer.append(TEXT_3);
    stringBuffer.append(GeneratorUtils.getServiceClassName(genClass));
    stringBuffer.append(TEXT_4);
    stringBuffer.append(genModel.getImportedName("com.google.web.bindery.requestfactory.shared.Locator"));
    stringBuffer.append(TEXT_5);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_6);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_8);
     if (genClass.isAbstract()) { 
    stringBuffer.append(TEXT_9);
     } else  {
    stringBuffer.append(TEXT_10);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_11);
     } 
    stringBuffer.append(TEXT_12);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_15);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_16);
    stringBuffer.append(genModel.getImportedName("ModelService"));
    stringBuffer.append(TEXT_17);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_18);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_19);
    stringBuffer.append(genClass.getImportedClassName());
    stringBuffer.append(TEXT_20);
    genModel.emitSortedImports();
    stringBuffer.append(TEXT_21);
    return stringBuffer.toString();
  }
}
